<?php


class UserDate
{

    /**
     * 当前时间
     * @var int
     */
    private $currentTime = 0;

    /**
     * 目标时间
     * @var int
     */
    private $tarGetTime = 0;

    /**
     * 每天的秒数
     * @var int
     */
    public static $DAY = 86400;
    /**
     * 每周的秒数
     * @var int
     */
    public static $WEEK = 604800;
    /**
     * 每月的秒数
     * @var int
     */
    public static $MONTH = 2419200;
    /**
     * 每年的秒数
     * @var int
     */
    public static $YEAR = 29030400;

    public function __construct(int $tarGetData = 0)
    {
        date_default_timezone_set("PRC");
        $this->currentTime = time();
        if ($tarGetData == 0) {
            $this->tarGetTime = time();
        } else {
            $this->tarGetTime = $tarGetData;
        }
    }

    /**
     * 判断是否过期
     * @return bool
     */
    public function isPastTimes()
    {
        if ($this->currentTime > $this->tarGetTime) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * @return int
     */
    public function getTarGetTime(): int
    {
        return $this->tarGetTime;
    }

    /**
     * 获取还剩多长时间
     * @return false|int|string
     */

    public function getHowLongTime()
    {
        if (!$this->isPastTimes()) {
            return 0;
        } else {
            return $this->tarGetTime - $this->currentTime;
        }
    }

    /**
     * 增加时间
     * @param int $time
     */

    public function plusTime(int $time)
    {
        $this->tarGetTime += $time;
    }

    /**
     * 减少时间
     * @param int $time
     */

    public function reduceTime(int $time)
    {
        $this->tarGetTime -= $time;
    }

}